<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目编辑</title>
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/metro/easyui.css"
	rel="stylesheet" />
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/mobile.css"
	rel="stylesheet" />
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/css/common.css"
	rel="stylesheet" />
<style type="text/css">
.content-tab ul {
	padding: 0px;
	margin: 0px;
}
span.datebox{
height:30px!important;
}
span.datebox{
height:30px!important;
}
span.datebox span a.textbox-icon{
height:30px!important;
}
span.datebox input.textbox-text{
padding-top:8px!important;
}
</style>
</head>
<body>

	<div>
		<!--导航栏-->
		<div class="line10"></div>
		<!--/导航栏-->

		<!--内容-->
		<div id="floatHead" class="content-tab-wrap">
			<div class="content-tab">
				<div class="content-tab-ul-wrap">
					<ul>
						<li><a class="selected" href="javascript:;">项目编辑</a></li>
					</ul>
				</div>
			</div>
		</div>

		<div class="tab-content">
			<dl>
				<dt>项目编码</dt>
				<dd>
					<input id="CODE" disabled="disabled" class="input normal"></input><span
						class="Validform_checktip"> 系统自动生成，不可修改</span>
				</dd>
			</dl>
			<dl>
				<dt>项目名称</dt>
				<dd>
					<input id="NAME" name="CODE" class="input normal"></input> <span
						class="Validform_checktip">*必填</span>
				</dd>
			</dl>
			<dl>
				<dt>项目大类</dt>
				<dd>
					<input id="HCATEGORY" style="height: 32px;" class="input normal"></input> <span
						class="Validform_checktip">*必填</span>
				</dd>
			</dl>
			<dl>
				<dt>项目类别</dt>
				<dd>
					<input id="PARENT" style="height: 32px;" class="input normal"></input> <span
						class="Validform_checktip">*必填</span>
				</dd>
			</dl>
			<dl>
				<dt>项目状态</dt>
				<dd>
					<input id="STATUS" style="height: 32px;" class="input normal"></input>
					<span class="Validform_checktip"></span>
				</dd>
			</dl>
			<dl>
				<dt>招募人数</dt>
				<dd>
					<input id="PERSON_NUMBER" class="input normal"></input>
					<span class="Validform_checktip">*必填，数字类型</span>
				</dd>
			</dl>
			<dl>
				<dt>性别要求</dt>
				<dd>
					<input id="SEX" style="height: 32px;" class="input normal"></input>
					<span class="Validform_checktip"></span>
				</dd>
			</dl>
			<dl>
				<dt>婚姻要求</dt>
				<dd>
					<input id="MARRIAGE" style="height: 32px;" class="input normal"></input>
					<span class="Validform_checktip"></span>
				</dd>
			</dl>
			<dl>
				<dt>年龄要求</dt>
				<dd>
					<input id="AGE_START" class="input small"></input> 到 <input id="AGE_END" class="input small"></input>
					<span class="Validform_checktip">*必填，数字类型</span>
				</dd>
			</dl>
			<dl>
				<dt>适应专业</dt>
				<dd>
					<input id="SPECIALITIES" class="input normal"></input>
					<span class="Validform_checktip"></span>
				</dd>
			</dl>
			<dl>
				<dt>适应疾病</dt>
				<dd>
					<input id="DISEASE" class="input normal"></input>
					<span class="Validform_checktip"></span>
				</dd>
			</dl>
			<dl>
				<dt>起止日期</dt>
				<dd>
					<input id="START_DATE" class="easyui-datebox" data-options="onSelect:onSelect" type="text"></input>
					<span>-</span>
					<input id="END_DATE" class="easyui-datebox" data-options="onSelect:onSelect" type="text"></input>
				</dd>
			</dl>
			<dl>
				<dt>联系人</dt>
				<dd>
					<input id="CONTACTS" class="input normal"></input>
					<span class="Validform_checktip"></span>
				</dd>
			</dl>
			<dl>
				<dt>联系方式</dt>
				<dd>
					<input id="PHONE_NUMBER" class="input normal"></input>
					<span class="Validform_checktip"></span>
				</dd>
			</dl>											
			<dl>
				<dt>项目介绍</dt>
				<dd>
					<textarea id="INTRODUCE" name="MEMO" style="width:500px;height:150px;" class="input"></textarea>
					<span class="Validform_checktip">最多2000个字符</span>
				</dd>
			</dl>
			<dl>
				<dt>入排标准</dt>
				<dd>
					<textarea id="STANDARD" name="MEMO" style="width:500px;height:150px;" class="input"></textarea>
					<span class="Validform_checktip">最多2000个字符</span>
				</dd>
			</dl>
			<dl>
				<dt>关于研究</dt>
				<dd>
					<textarea id="RESEARCH" name="MEMO" style="width:500px;height:150px;" class="input"></textarea>
					<span class="Validform_checktip">最多2000个字符</span>
				</dd>
			</dl>			
		</div>
		<!--/内容-->

		<!--工具栏-->
		<div class="page-footer">
			<div class="btn-wrap">
				<button id='btnSave' class="btn" onclick="save()">提交保存</button>
				<input name="btnReturn" type="button" value="返回上一页"
					class="btn yellow" onclick="javascript:history.back(-1);" />
			</div>
		</div>
		<!--/工具栏-->
	</div>
	<input type="hidden" id="code" value="${code}" />
	<input type="hidden" id="action" value="${action}" />
	<input type="hidden" id="show" value="${show}" />
	<script
		src="${pageContext.request.contextPath}/assets/js/jquery-1.11.2.min.js"
		charset="utf-8" type="text/javascript"></script>
	<script
		src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/jquery.easyui.min.js"
		charset="utf-8" type="text/javascript"></script>
	<script
		src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"
		charset="utf-8" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/assets/js/common.js" type="text/javascript" charset="utf-8">
	</script>
	<script type="text/javascript">
		var action = $('#action').val();
		var contextPath = '<%=request.getContextPath()%>';
		$(function() {
			if (action == 'add'){
				$('.content-tab-ul-wrap a').html('新增项目');
				getMaxItem();
			}
			else{
				$('.content-tab-ul-wrap a').html('修改项目');	
			}	
			if($('#show').val()=='1'){
				$('#btnSave').css('display','none');
				$('.content-tab-ul-wrap a').html('查看项目');
			}
			getCombobox();
			//校验新增项目编码是否已经存在
			$('#CODE').blur(function(){
				if(action=='add'){
					if(!$.isNullOrEmpty($('#CODE').val())){
						$.ajax({
							url : contextPath + "/bg/IM104.do",
							data : {"code":$('#CODE').val(),"rnd":Math.random()},
							dataType : 'json',
							success : function(data, textStatus, jqXHR) {
								if(data.status=='true'){
									$.messager.show({title:'提示',msg:'项目编码已存在！',showType:'slide'});
									$('#CODE').val('');
									$('#CODE').focus();
								}
							}
						});
					}
				}
			});
			
		})
		//获取combobox
		function getCombobox() {
			$.ajax({
				url : contextPath + "/bg/IM102.do",
				data : {
					"rnd" : Math.random()
				},
				dataType : 'json',
				success : function(data, textStatus, jqXHR) {
					//var category = data.category;
					var status=data.status;
					var sex=data.sex;
					var marriage=data.marriage;
					var hcategory=data.hcategory;
					$('#HCATEGORY').combobox({
						data : eval("(" + func(hcategory) + ")"),
						valueField : 'id',
						textField : 'text',
						onSelect:function(record){
							$.ajax({
								url : contextPath + "/bg/IM114.do",
								data : {
									"PARENT_CODE":record.id,
									"rnd" : Math.random()
								},
								dataType : 'json',
								success:function(data, textStatus, jqXHR){
									var category = data.category;
									$('#PARENT').combobox({
										data : eval("(" + func(category) + ")"),
										valueField : 'id',
										textField : 'text'
									});
								}
							})
						}
					});
/* 					$('#PARENT').combobox({
						data : eval("(" + func(category) + ")"),
						valueField : 'id',
						textField : 'text'
					}); */
					$('#STATUS').combobox({
						data : eval("(" + func(status) + ")"),
						valueField : 'id',
						textField : 'text'
					});	
					$('#STATUS').combobox("setValue",'0');
					var sexObj=eval("(" + func(sex) + ")");
					//sexObj.push({ "text": "不限", "id": 0 });
					$('#SEX').combobox({
						data : sexObj,
						valueField : 'id',
						textField : 'text'
					});	
					$('#SEX').combobox("setValue",'0');
					var marriageObj=eval("(" + func(marriage) + ")");
					//marriageObj.push({ "text": "不限", "id": 0 });
					$('#MARRIAGE').combobox({
						data : marriageObj,
						valueField : 'id',
						textField : 'text'
					});		
					$('#MARRIAGE').combobox("setValue",'0');
					if(action=='edit'){
						var code=$('#code').val();
						setVal(code);
					}
				}
			})
		}
		//循环
		function func(result){
			var json = '';
			for (var j = 0; j < result.length; j++) {
				json += '{"id":"' + result[j].id + '","text":"'
						+ result[j].name + '"},'
			}
			if (json.length > 0) {
				json = json.substring(0, json.length - 1);
			}
			json = '[' + json + ']';
			return json;
		}
		//保存
		function save(){
			var param={};
			param.CODE = $('#CODE').val();
	  		if($.isNullOrEmpty(param.CODE)){
	  			$.messager.show({title:'提示',msg:'项目编码不能为空！',showType:'slide'});
	  			$('#CODE').focus();
	  			return;
	  		}
			param.NAME = $('#NAME').val();
	  		if($.isNullOrEmpty(param.NAME)){
	  			$.messager.show({title:'提示',msg:'项目名称不能为空！',showType:'slide'});
	  			$('#NAME').focus();
	  			return;
	  		}
			param.PARENT_CODE = $('#PARENT').combobox('getValue');
	  		if($.isNullOrEmpty(param.PARENT_CODE)){
	  			$.messager.show({title:'提示',msg:'项目类别不能为空！',showType:'slide'});
	  			$('#PARENT').focus();
	  			return;
	  		}
			param.STATUS = $('#STATUS').combobox('getValue');
			param.PERSON_NUMBER=$('#PERSON_NUMBER').val();
	  		if($.isNullOrEmpty(param.PERSON_NUMBER)){
	  			$.messager.show({title:'提示',msg:'招募人数不能为空！',showType:'slide'});
	  			$('#PERSON_NUMBER').focus();
	  			return;
	  		}else{
	  			if(isNaN(param.PERSON_NUMBER)){
		  			$.messager.show({title:'提示',msg:'招募人数必须为数字类型！',showType:'slide'});
		  			$('#PERSON_NUMBER').focus();
		  			return;
	  			}
	  		}
			param.SEX = $('#SEX').combobox('getValue');
			param.MARRIAGE = $('#MARRIAGE').combobox('getValue');
			param.AGE_START = $('#AGE_START').val();
	  		if($.isNullOrEmpty(param.AGE_START)){
	  			$.messager.show({title:'提示',msg:'年龄要求不能为空！',showType:'slide'});
	  			$('#AGE_START').focus();
	  			return;
	  		}else{
	  			if(isNaN(param.AGE_START)){
		  			$.messager.show({title:'提示',msg:'年龄要求必须为数字类型！',showType:'slide'});
		  			$('#AGE_START').focus();
		  			return;
	  			}
	  		}
			param.AGE_END = $('#AGE_END').val();
	  		if($.isNullOrEmpty(param.AGE_END)){
	  			$.messager.show({title:'提示',msg:'年龄要求不能为空！',showType:'slide'});
	  			$('#AGE_END').focus();
	  			return;
	  		}else{
	  			if(isNaN(param.AGE_END)){
		  			$.messager.show({title:'提示',msg:'年龄要求必须为数字类型！',showType:'slide'});
		  			$('#AGE_END').focus();
		  			return;
	  			}
	  		}
	  		if(parseInt(param.AGE_END)<parseInt(param.AGE_START)){
	  			$.messager.show({title:'提示',msg:'开始年龄要小于结束年龄！',showType:'slide'});
	  			$('#AGE_START').focus();
	  			return;
	  		}
			param.SPECIALITIES = $('#SPECIALITIES').val();
			param.DISEASE=$('#DISEASE').val();
			param.START_DATE=$('#START_DATE').datebox('getValue');
			param.END_DATE=$('#END_DATE').datebox('getValue');
			param.CONTACTS=$('#CONTACTS').val();
			param.PHONE_NUMBER=$('#PHONE_NUMBER').val();
			param.INTRODUCE=$('#INTRODUCE').val();
			if(param.INTRODUCE.length>2000){
				$.messager.alert('警告','项目介绍过长，超过2000个字符！');
				return;
			}
			param.STANDARD=$('#STANDARD').val();
			if(param.STANDARD.length>2000){
				$.messager.alert('警告','参考标准过长，超过2000个字符！');
				return;
			}
			param.RESEARCH=$('#RESEARCH').val();
			if(param.RESEARCH.length>2000){
				$.messager.alert('警告','关于研究过长，超过2000个字符！');
				return;
			}
			param.RND=Math.random();
			param.action=action;
			$.ajax({
				url : contextPath + "/bg/IM103.do",
				data : param,
				dataType : 'json',
				success : function(data, textStatus, jqXHR) {
					if(data.status=='true'){
						$.messager.show({title:'提示',msg:'保存成功！',showType:'slide'});
						//location.href=contextPath+"/bg/item.do";
					}else{
						$.messager.show({title:'提示',msg:'保存失败！',showType:'slide'});
					}
				}
			})
		}
		//赋值
		function setVal(code){
			$.ajax({
				url : contextPath + "/bg/IM104.do",
				data : {"code":code,"rnd":Math.random()},
				dataType : 'json',
				success : function(data, textStatus, jqXHR) {
					var result=data.result;
					$('#CODE').val(result.CODE);
					$('#NAME').val(result.NAME);
					$('#HCATEGORY').combobox('setValue',result.HCATEGORY_CODE);
					$.ajax({
						url : contextPath + "/bg/IM114.do",
						data : {
							"PARENT_CODE":result.HCATEGORY_CODE,
							"rnd" : Math.random()
						},
						dataType : 'json',
						success:function(data, textStatus, jqXHR){
							var category = data.category;
							$('#PARENT').combobox({
								data : eval("(" + func(category) + ")"),
								valueField : 'id',
								textField : 'text'
							});
							$('#PARENT').combobox('setValue',result.PARENT_CODE);
						}
					})
					$('#STATUS').combobox('setValue',result.STATUS);
					$('#PERSON_NUMBER').val(result.PERSON_NUMBER);
					$('#SEX').combobox('setValue',result.SEX);
					$('#MARRIAGE').combobox('setValue',result.MARRIAGE);
					$('#AGE_START').val(result.AGE_START);
					$('#AGE_END').val(result.AGE_END);
					$('#SPECIALITIES').val(result.SPECIALITIES);
					$('#DISEASE').val(result.DISEASE);
					$('#START_DATE').datebox('setValue',result.START_DATE);
					$('#END_DATE').datebox('setValue',result.END_DATE);
					$('#CONTACTS').val(result.CONTACTS);
					$('#PHONE_NUMBER').val(result.PHONE_NUMBER);
					$('#INTRODUCE').val(result.INTRODUCE);
					$('#STANDARD').val(result.STANDARD);
					$('#RESEARCH').val(result.RESEARCH);
				}
			})
		}
		//日期选中事件
		function onSelect(date){
			var start_date=$("#START_DATE").datebox('getValue');
			var end_date=$("#END_DATE").datebox('getValue');
			var d1 = new Date(start_date.replace(/\-/g, "\/")); 
			var d2 = new Date(end_date.replace(/\-/g, "\/"));  
			if(start_date!=""&&end_date!="") 
			{ 
				if(d1>d2){
		  			$.messager.show({title:'提示',msg:'项目开始日期不能大于结束日期！',showType:'slide'});
		  			$('#START_DATE').focus();
					return; 
				}
			}
		}
		//获取项目编码
		function getMaxItem(){
			$.ajax({
				url : contextPath + "/bg/IM115.do",
				type:"post",
				data : {
					"rnd" : Math.random()
				},
				dataType : 'json',
				success:function(data, textStatus, jqXHR){
					$('#CODE').val(data.MAX_CODE);
				}
			})
		}
	</script>
</body>
</html>